home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-04-28 | 6.2 KB | 167 lines | [TEXT/MPS ] |
- PRINT OFF
- INCLUDE 'Traps.a'
- INCLUDE 'SANEMacs.a'
- PRINT ON
- ;-------------------------------------------------
- Mxmpy PROC EXPORT
- ;- - - - - - - - - - - - - - - - - - - - - - - - -
- ; Performs the matrix multiplication C = A * B.
- ;
- ; Calling sequence (FORTRAN):
- ; CALL MXMPY (A, B, C, L, M, N)
- ;
- ; where
- ; A is an array with L rows and M columns
- ; B is an array with M rows and N columns
- ; C is an array with L rows and N columns
- ; L, M, and N are INTEGERs.
- ;
- ; NOTE: All arrays must be completely filled,
- ; with no gaps. Do not try to pass part of an
- ; array unless it forms a contiguous block of
- ; memory locations.
- ;
- ; April 1990
- ; Jon Bell, Dept. of Physics & Computer Science
- ; Presbyterian College, Clinton SC 29325
- ;
- ; Written for MPW Assembler, v3.0.
- ;- - - - - - - - - - - - - - - - - - - - - - - - -
- ; Locations of arguments to the subroutine,
- ; relative to the address stored in register A6.
- a EQU 28 ; addr. of a
- b EQU 24 ; addr. of b
- c EQU 20 ; addr. of c
- l EQU 16 ; addr. of # rows in a
- m EQU 12 ; addr. of # cols in a
- n EQU 8 ; addr. of # cols in b
- ; Locations of local variables, relative to the
- ; address stored in register A6.
- sum EQU -10 ; accumulates an element of c
- term EQU -20 ; terms for an element of c
- termCount EQU -24 ; initial value of term index
- rowCount EQU -28 ; initial value of col. index
- aColSize EQU -32 ; # of bytes per column of a
- bColSize EQU -36 ; # of bytes per column of b
- ; Other constants.
- ParamSize EQU 24 ; # of bytes of parameters
- LocalSize EQU -36 ; # of bytes of local var's.
- ; Register usage.
- aPtr EQU A2 ; pointer into a
- bPtr EQU A3 ; pointer into b
- cPtr EQU A4 ; pointer into c
- rowIndex EQU D3 ; row-loop index
- colIndex EQU D4 ; column-loop index
- termIndex EQU D5 ; term-loop index
- aRowBase EQU D6 ; start of current row in a
- bColBase EQU D7 ; start of current col. in b
- ;- - - - - - - - - - - - - - - - - - - - - - - - -
- ; Set up the stack frame, and save registers on
- ; the stack.
- LINK A6, #LocalSize
- MOVEM.L A2-A4/D3-D7, -(SP)
- ; Calculate and save the length of one
- ; column of a.
- MOVE.L l(A6), A0
- MOVE.L (A0), D0 ; # of rows
- MULU #10, D0 ; bytes per column
- MOVE.L D0, aColSize(A6)
- ; Calculate and save the length of one
- ; column of b.
- MOVE.L m(A6), A0
- MOVE.L (A0), D0 ; # of rows
- MULU #10, D0 ; bytes per column
- MOVE.L D0, bColSize(A6)
- ; Save the initial value of the term index.
- MOVE.L m(A6), A0
- MOVE.L (A0), termCount(A6)
- ; Save the initial value of the row index.
- MOVE.L l(A6), A0
- MOVE.L (A0), rowCount(A6)
- ; Initialize the column index.
- MOVE.L n(A6), A0
- MOVE.L (A0), colIndex
- ; Initialize the base address of the current
- ; column in b to the start of b.
- MOVE.L b(A6), bColBase
- ; Initialize pointer into c.
- MOVE.L c(A6), cPtr
- BeginColLoop ; Cycle over the columns of c.
- SUB.L #1, colIndex
- BMI.S EndColLoop
- ; Initialize the row index.
- MOVE.L rowCount(A6), rowIndex
- ; Initialize the base address of the
- ; current row in a to the start of a.
- MOVE.L a(A6), aRowBase
- BeginRowLoop ; Cycle over the rows of c.
- SUB.L #1, rowIndex
- BMI.S EndRowLoop
- ; Initialize the a and b pointers
- ; for the next sum of terms.
- MOVE.L aRowBase, aPtr
- MOVE.L bColBase, bPtr
- ; Initialize the sum.
- LEA sum(A6), A0
- CLR.L (A0)+
- CLR.L (A0)+
- CLR.W (A0)
- ; Initialize the term index.
- MOVE.L termCount(A6), termIndex
- BeginTermLoop ; Cycle over the terms
- ; in the sum.
- SUB.L #1, termIndex
- BMI.S EndTermLoop
- ; Push the source and
- ; destination addresses on the
- ; stack for the multiplication.
- MOVE.L aPtr, -(SP)
- LEA term(A6), A0
- MOVE.L A0, -(SP)
- ; Copy the current element of b
- ; to the destination, and
- ; advance to the next element
- ; in the current column of b.
- MOVE.L (bPtr)+, (A0)+
- MOVE.L (bPtr)+, (A0)+
- MOVE.W (bPtr)+, (A0)
- ; Perform the multiplication.
- FMULX
- ; Add the new term to the sum.
- PEA term(A6)
- PEA sum(A6)
- FADDX
- ; Advance to the next element
- ; in the current row of a.
- ADDA.L aColSize(A6), aPtr
- BRA.S BeginTermLoop
- EndTermLoop
- ; Move the sum into the current
- ; element of c, and advance to the
- ; next row in the current column of
- ; c. (At the end of the current
- ; column, this will wrap around to
- ; the next column.)
- LEA sum(A6), A0
- MOVE.L (A0)+, (cPtr)+
- MOVE.L (A0)+, (cPtr)+
- MOVE.W (A0), (cPtr)+
- ; Advance to the next row of a.
- ADD.L #10, aRowBase
- BRA.S BeginRowLoop
- EndRowLoop
- ; Advance to the next column of b.
- ADD.L bColSize(A6), bColBase
- BRA.S BeginColLoop
- EndColLoop
- ; All done. Restore the saved registers,
- ; clean up the stack and return.
- MOVEM.L (SP)+, A2-A4/D3-D7
- UNLK A6
- MOVE.L (SP)+, A0
- ADDA.L #ParamSize, SP
- JMP (A0)
- DC.B 'MXMPY ' ; label for debugger
- ENDPROC
- END
-